// main.go
package main

import (
	"fmt"
	"time"

	"gitee.com/Flearning/go_crawl/setting"
	"gopkg.in/go-module/log.v1"
)

func main() {
	setting.NewConfigContext()
	setting.NewLogService()

	crawlRate := setting.RateCrawl

	dayLayout := "2006-01-02"
	layout := "2006-01-02 15:04:05"

	loc, _ := time.LoadLocation("Asia/Shanghai")
	for {
		now := time.Now()
		toDay := now.Format(dayLayout)
		start := fmt.Sprintf("%s %s", toDay, crawlRate.StartTime)
		end := fmt.Sprintf("%s %s", toDay, crawlRate.EndTime)
		theUnixTime := now.Unix()
		timeStart, _ := time.ParseInLocation(layout, start, loc)
		timeEnd, _ := time.ParseInLocation(layout, end, loc)

		toWeekday := now.Weekday()

		// fmt.Println(theUnixTime, timeStart.Unix(), timeEnd.Unix())
		log.Info("the time: %s -- startTime: %s --- endTime: %s", now.String(), timeStart.String(), timeEnd.String())
		log.Info("the day weekday: %d", int(toWeekday))
		if theUnixTime < timeEnd.Unix() && theUnixTime > timeStart.Unix() {
			getTestStr()
		}
		time.Sleep(time.Duration(crawlRate.Rate*1000) * time.Millisecond)
	}

}

func getTestStr() {

	fmt.Println(time.Now().String())
	log.Info(time.Now().String())
}
